﻿Imports System
Imports System.Diagnostics

Namespace System.Workflow.Runtime
    Friend Class WorkflowTraceTransfer
        Implements IDisposable
        ' Methods
        Public Sub New(ByVal instanceId As Guid)
            If Not Me.oldGuid.Equals(instanceId) Then
                WorkflowTrace.Runtime.TraceTransfer(0, Nothing, instanceId)
                Trace.CorrelationManager.ActivityId = instanceId
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Start, 0, "Workflow Trace")
                Me.transferBackAtClose = True
            End If
        End Sub

        Public Sub Dispose()
            If Me.transferBackAtClose Then
                WorkflowTrace.Runtime.TraceTransfer(0, Nothing, Me.oldGuid)
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Stop, 0, "Workflow Trace")
                Trace.CorrelationManager.ActivityId = Me.oldGuid
            End If
        End Sub


        ' Fields
        Private oldGuid As Guid = Trace.CorrelationManager.ActivityId
        Private transferBackAtClose As Boolean
    End Class
End Namespace

